home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Found / FWDebug / Sources / SLDebug.cpp < prev   
Encoding:
Text File  |  1996-04-25  |  4.4 KB  |  171 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPriDeb.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993-1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFound.hpp"
  11.  
  12. // Need to include first so that FW_DEBUG is properly defined
  13.  
  14. #ifndef FWPRIDEB_H
  15. #include "FWPriDeb.h"
  16. #endif
  17.  
  18. #ifndef FWPRISTR_H
  19. #include "FWPriStr.h"
  20. #endif
  21.  
  22. #ifndef FWPRIMEM_H
  23. #include "FWPriMem.h"
  24. #endif
  25.  
  26. #if defined(FW_BUILD_MAC) && !defined(__TYPES__)
  27. #include <Types.h>
  28. #endif
  29.  
  30. #if defined(THINK_CPLUS) && !defined(__PASCAL__)
  31. #include <Pascal.h>
  32. #endif
  33.  
  34. #if defined(FW_BUILD_WIN) && !defined(_INC_WINDOWS)
  35. #include <Windows.h>
  36. #endif
  37.  
  38. #ifdef FW_BUILD_MAC
  39. #pragma segment FWDebug
  40. #endif
  41.  
  42.  
  43. //----------------------------------------------------------------------------------------
  44. // privDebugger
  45. //----------------------------------------------------------------------------------------
  46. extern "C" void privDebugger(FW_SDebugConsole* self);
  47.  
  48. void privDebugger(FW_SDebugConsole* self)
  49. {
  50. FW_UNUSED(self);
  51. #if defined(FW_BUILD_WIN)
  52. #ifndef FW_BUILD_DOS
  53.     ::DebugBreak();
  54. #endif
  55.  
  56. #elif defined(FW_BUILD_MAC)
  57.     ::Debugger();
  58. #endif
  59. }
  60.  
  61. #if defined(FW_BUILD_MAC) && !defined(CGLUESUPPORTED)
  62. //----------------------------------------------------------------------------------------
  63. // fwctop
  64. //----------------------------------------------------------------------------------------
  65.  
  66. static void fwctop(char* s)
  67. {
  68.     int len = FW_PrimitiveStringLength(s);
  69.     FW_PrimitiveCopyMemory(s, s+1, len);
  70.     s[0] = len;
  71. }
  72.  
  73. //----------------------------------------------------------------------------------------
  74. // fwptoc
  75. //----------------------------------------------------------------------------------------
  76.  
  77. static void fwptoc(char* s)
  78. {
  79.     int len = s[0];
  80.     FW_PrimitiveCopyMemory(s+1, s, len);
  81.     s[len] = 0;
  82. }
  83.  
  84. //----------------------------------------------------------------------------------------
  85. // debugstr
  86. //----------------------------------------------------------------------------------------
  87. static void debugstr(const char *message)
  88. {
  89.     fwctop((char*) message);
  90.     DebugStr((const unsigned char*) message);
  91.     fwptoc((char*) message);
  92. }
  93. #endif
  94.  
  95. //----------------------------------------------------------------------------------------
  96. // privDebugMessage
  97. //----------------------------------------------------------------------------------------
  98. extern "C" void privDebugMessage(FW_SDebugConsole* self, const char* message);
  99.  
  100.  
  101. void privDebugMessage(FW_SDebugConsole* self, const char* message)
  102. {
  103. #if defined(FW_BUILD_WIN)
  104. #ifndef FW_BUILD_DOS
  105.     ::OutputDebugString(message);
  106.     ::OutputDebugString("\n\r");
  107.     ::DebugBreak();
  108.     if (self->fPrivate != 0)
  109.     {
  110.         ::OutputDebugString("Oh, by the way, self->fPrivate should be 0\n\r");
  111.         ::DebugBreak();
  112.     }
  113. #endif
  114.  
  115. #elif defined(FW_BUILD_MAC)
  116.     ::debugstr(message);
  117.     if (self->fPrivate != 0)
  118.         ::debugstr("Oh, by the way, self->fPrivate should be 0");
  119. #endif
  120. }
  121.  
  122.  
  123. //----------------------------------------------------------------------------------------
  124. // If FW_DEBUG is defined, there is a default debug console.  The default console uses 
  125. // whatever debugging packages are available.  If FW_DEBUG is undefined, there is no 
  126. // default debug console.   
  127. //----------------------------------------------------------------------------------------
  128. #ifdef FW_DEBUG
  129. #define FW_DEBUG_CONSOLE &sDebugConsole
  130.  
  131. static FW_SDebugConsole sDebugConsole =
  132. {
  133.     privDebugMessage,
  134.     privDebugMessage,
  135.     privDebugMessage,
  136.     privDebugMessage,
  137.     privDebugger
  138. };
  139. #else
  140. #define FW_DEBUG_CONSOLE {0}
  141. #endif
  142.  
  143.  
  144.  
  145. static FW_SDebugConsole *gDebugConsole = FW_DEBUG_CONSOLE;
  146.  
  147.  
  148. //----------------------------------------------------------------------------------------
  149. // FW_PrivDebugConsole_GetConsole
  150. //----------------------------------------------------------------------------------------
  151.  
  152. FW_EXPORT FW_SDebugConsole* FW_PrivDebugConsole_GetConsole()
  153. {
  154.     // No try block necessary - Do not throw
  155.     return gDebugConsole;
  156. }
  157.  
  158. //----------------------------------------------------------------------------------------
  159. // FW_PrivDebugConsole_SetConsole
  160. //----------------------------------------------------------------------------------------
  161.  
  162. FW_EXPORT FW_SDebugConsole* FW_PrivDebugConsole_SetConsole(FW_SDebugConsole* console)
  163. {
  164.     // No try block necessary - Do not throw
  165.     FW_SDebugConsole* prior = gDebugConsole;
  166.     gDebugConsole = console;
  167.     return prior;
  168. }
  169.  
  170.  
  171.